home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / brailler-04b-c / brlr ƒ / Shell ƒ / environment.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  3.5 KB  |  107 lines  |  [TEXT/MMCC]

  1. #include "environment.h"
  2. #include "apple events.h"
  3. #include "error.h"
  4. #include "program globals.h"
  5. #include "GestaltEqu.h"
  6. #include "Traps.h"
  7.  
  8. Boolean            gHasColorQD;                /* color Quickdraw present? */
  9. Boolean            gHasNotificationManager;    /* notification manager present? (cf error.c) */
  10.  
  11. short            gForegroundWaitTime;        /* WaitNextEvent sleep time while in frgrnd */
  12. short            gBackgroundWaitTime;        /* WaitNextEvent sleep time while in bkgrnd */
  13. Boolean            gIsInBackground;            /* program is in background currently? */
  14. Boolean            gInProgress;                /* progress bar up? */
  15. Boolean            gDone;                        /* program done? */
  16. Boolean            gFrontWindowIsOurs;            /* frontmost window is one of ours? */
  17. short            gFrontWindowIndex;            /* gTheWindowData[] index of front window, if ours */
  18. Boolean            gIsVirgin;                    /* first time running? */
  19. Boolean            gCustomCursor;                /* front window is using custom cursor ? */
  20. short            gKludgeIter;
  21. Boolean            gNeedToOpenWindow;
  22.  
  23. /* This is to stop the compiler from using Gestalt glue without killing
  24.    all the other pre-system 7 glue for other routines. */
  25. #pragma parameter __D0 RealGestalt(__D0,__A1)
  26. pascal OSErr RealGestalt(OSType selector,long *response) = {0xA1AD,0x2288};
  27. #define        Gestalt            RealGestalt
  28. #define        GESTALT_TRAP    0xA1AD            /* _Gestalt */
  29.  
  30. #define    GetTrapType(T)    (((T & 0x0800) > 0) ? ToolTrap : OSTrap)
  31. #define NumToolboxTraps()    ((NGetTrapAddress(_InitGraf, ToolTrap) ==    \
  32.                             NGetTrapAddress(0xAA6E, ToolTrap)) ? 0x0200    \
  33.                             : 0x0400)
  34.  
  35. Boolean TrapAvailable(short theTrap);
  36.  
  37. Boolean TrapAvailable(short theTrap)
  38. {
  39.     TrapType        tType;
  40.     
  41.     tType=GetTrapType(theTrap);
  42.     if (tType==ToolTrap)
  43.     {
  44.         theTrap=theTrap&0x07FF;
  45.         if (theTrap>=NumToolboxTraps())
  46.             theTrap=_Unimplemented;
  47.     }
  48.     return (NGetTrapAddress(theTrap, tType)!=NGetTrapAddress(_Unimplemented, ToolTrap));
  49. }
  50.  
  51. Boolean InitTheEnvironment(void)
  52. /* called very early -- this uses Gestalt to check out the computing environment;
  53.    see above for explanations of variables */
  54. {
  55.     long            gestalt_temp;
  56.     OSErr            isHuman;
  57.     SysEnvRec        theWorld;
  58.     
  59.     if (SysEnvirons(1, &theWorld)==envNotPresent)
  60.         return FALSE;
  61.     
  62.     if (!TrapAvailable(_WaitNextEvent))
  63.         return FALSE;
  64.     
  65.     if (!TrapAvailable((short)GESTALT_TRAP))
  66.         return FALSE;
  67.  
  68.     isHuman=Gestalt(gestaltSystemVersion, &gestalt_temp);
  69.     if (isHuman || (gestalt_temp < 1792))
  70.         return FALSE;
  71.     
  72.     isHuman=Gestalt(gestaltQuickdrawVersion, &gestalt_temp);
  73.     gHasColorQD=!(isHuman || (gestalt_temp < gestalt8BitQD));
  74.  
  75.     isHuman=Gestalt(gestaltFSAttr, &gestalt_temp);
  76.     if (!((isHuman==noErr) && (gestalt_temp&(1<<gestaltHasFSSpecCalls))))
  77.         return FALSE;
  78.  
  79.     isHuman=Gestalt(gestaltStandardFileAttr, &gestalt_temp);
  80.     if (!((isHuman==noErr) && (gestalt_temp&(1<<gestaltStandardFile58))))
  81.         return FALSE;
  82.  
  83.     isHuman=Gestalt(gestaltNotificationMgrAttr, &gestalt_temp);
  84.     gHasNotificationManager=(!((isHuman) ||
  85.         (((gestalt_temp >> gestaltNotificationPresent) & 0x01) != 1)));
  86.     
  87.     isHuman=Gestalt(gestaltAppleEventsAttr, &gestalt_temp);
  88.     if (!((!isHuman) && (gestalt_temp&(1<<gestaltAppleEventsPresent))))
  89.         return FALSE;
  90.     
  91.     InstallRequiredAppleEvents();
  92.     
  93.     gForegroundWaitTime=10;            /* WaitNextEvent sleep time when we're in frgrnd */
  94.     gBackgroundWaitTime=100;        /* WaitNextEvent sleep time when we're in bkgrnd */
  95.     gDone=FALSE;                    /* TRUE if program is done (exit event loop) */
  96.     gInProgress=FALSE;                /* TRUE if progress bar is up */
  97.     gIsInBackground=FALSE;            /* TRUE if program is in background */
  98.     gPendingResultCode=allsWell;    /* set to error code if error occurs while in bkgrnd */
  99.     gFrontWindowIsOurs=FALSE;
  100.     gFrontWindowIndex=0;
  101.     gCustomCursor=FALSE;
  102.     gKludgeIter=0;
  103.     gNeedToOpenWindow=TRUE;
  104.  
  105.     return TRUE;
  106. }
  107.